<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .viewNav {
        width: 160px;
        height: 36px;
        line-height: 36px;
        background: #FFFFFF;
    }

    .viewNav:after, .viewNavBox:after {
        content: '';
        display: block;
        clear: both;
    }

    .viewNav div {
        text-align: center;
        float: left;
        cursor: pointer;
        width: 79px;
        height: 36px;
        box-sizing: border-box;
        border: 1px solid #CCCCCC;
        font-size: 14px;
        font-family: Microsoft YaHei-Regular, Microsoft YaHei;
        font-weight: 400;
        color: #999999;
    }

    .viewNav div img {
        width: 20px;
        height: 20px;
        vertical-align: text-top;
    }

    .viewNav .viewNavList {
        border-right: none;
        border-radius: 5px 0 0 5px;
    }

    .viewNav .viewNavGraphics {
        border-radius: 0px 5px 5px 0px;
        border-left: none;
    }

    .viewNav > span {
        float: left;
        width: 1px;
        height: 36px;
        background-color: #0A8B0A;
    }

    .viewNav .active {
        color: #0A8B0A;
        border-color: #0A8B0A;
    }

    .viewNavMain {
        display: none;
        min-width: 1602px;
        overflow: hidden;
    }


    .viewNavBoxList {
        box-sizing: border-box;
        width: 210px;
        height: 270px;
        float: left;
        border: 1px solid #EDEDED;
        border-radius: 10px;
        margin-right: 20px;
        margin-bottom: 20px;
        position: relative;
        cursor: pointer;
        font-family: Microsoft YaHei-Regular, Microsoft YaHei;
    }

    .viewNavBoxList:nth-child(7n) {
        margin-right: 0;
    }

    .viewNavBoxList .viewNavBoxSpaceNum {
        width: 72px;
        height: 32px;
        box-sizing: border-box;
        position: absolute;
        left: 0;
        top: 8px;
        background-image: url('assets/images/spaceNum.png');
        line-height: 32px;
        text-align: center;
    }

    .viewNavBoxList .viewNavBoxListImg {
        margin: 20px 35px 0;
        width: 140px;
        height: 140px;
    }

    .viewNavBoxListImg img {
        width: 100%;
        height: 100%;
    }

    .viewNavBoxList .viewNavBoxListTitle {
        box-sizing: border-box;
        padding: 0 10px;
        margin-top: 14px;
        font-size: 16px;
        font-weight: bold;
        color: #333333;
        line-height: 19px;
        text-align: center;
        height: 40px;
        width: 100%;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
    }

    .viewNavBoxList .viewNavBoxListBottom {
        position: absolute;
        width: 100%;
        left: 0;
        bottom: 0;
        height: 40px;
        background: #FAFBFF;
        border-radius: 0 0 10px 10px;
        padding: 0 14px;
        box-sizing: border-box;
    }

    .viewNavBoxListBottom > span {
        box-sizing: border-box;
        text-align: center;
        line-height: 40px;
        font-size: 12px;
        font-weight: 400;
        color: #333333;
        float: left;
    }

    .viewNavBoxListBottom > span:last-child {
        float: right;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header" id="exportFrom">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt" style="width: calc(82% - 160px)">
                                <!--
                            <div class="query-lt" style="width: calc(82% - 160px)">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">称重柜类型：</label>
                                    <div class="layui-inline">
                                        <select name="productType" lay-filter="productType" lay-search lay-verify="">
                                            <option value=""> 请选称重柜类型</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">称重柜品牌：</label>
                                    <div class="layui-inline">
                                        <select name="productBrandId" lay-filter="productBrandId" lay-search
                                                lay-verify="">
                                            <option value="">请选称重柜品牌</option>
                                        </select>
                                    </div>
                                </div>
                                -->
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">柜子编号：</label>
                                    <div class="layui-inline">
                                        <select  name="cabCode" lay-filter="cabCode"  lay-search lay-verify="">
                                            <option value=""> 请选柜子</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-inline">
                                        <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <div class="viewNav" id="viewNav">
                                        <div class="viewNavList active"><img src="assets/images/navlist1.png">列表</div>
                                        <span></span>
                                        <div class="viewNavGraphics"><img src="assets/images/navgraphics.png">图文</div>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit>查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>

                                    <button id="storageInventoryInoutBtnExport" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="wcabCellSingleinventoryProductTable" lay-filter="wcabCellSingleinventoryProductTable"></table>
            <div class="viewNavMain" id="viewNavMain">
                <div class="viewNavBox" id="viewNavBox"></div>
                <div id="viewNavPage" style="text-align: right;"></div>
            </div>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="wcabCellSingleinventoryProductTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="inventorySpace">库存分布</a>
    <!--
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    -->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="storageInventoryInoutForm">
    <form lay-filter="storageInventoryInoutForm" class="layui-form model-form">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">柜子编号</label>
            <div class="layui-input-block">
                <input name="cabCode" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物料图片</label>
            <div class="layui-input-block">
                <img id="skuPic" src="" style="max-height: 80px; max-width: 500px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-block">
                <input name="skuName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物料编号</label>
            <div class="layui-input-block">
                <input name="skuCode" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-block">
                <input name="productBrandName" placeholder="" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">暂存数量</label>
            <div class="layui-input-block">
                <input name="quantityTemp" placeholder="" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">报修数量</label>
            <div class="layui-input-block">
                <input name="quantityRepair" placeholder="" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">报废数量</label>
            <div class="layui-input-block">
                <input name="quantityRecycle" placeholder="" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">分布车间数</label>
            <div class="layui-input-block">
                <input name="workshopNum" placeholder="" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">称重柜数</label>
            <div class="layui-input-block">
                <input name="cabNum" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">货位数</label>
            <div class="layui-input-block">
                <input name="spaceNum" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

    </form>
</script>


<script type="text/html" id="inventorySpaceTab">

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <!--
                            <label class="layui-form-label w-auto">称重柜编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="cabCode" class="layui-input" type="text" placeholder="请输入称重柜编号"/>
                            </div>
                            <label class="layui-form-label w-auto">物料编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"/>
                            </div>
                            -->
                            <label class="layui-form-label">货位编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="spaceCode" class="layui-input" type="text" placeholder="请输入货位编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" lay-submit><i
                                    class="layui-icon">&#xe615;</i>搜索
                            </button>
                            <!--
                            <button id="storageInventoryInoutBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                            -->
                        </div>
                    </div>
                </div>
                <!-- 表格 -->

                <table class="layui-table" id="wcabCellinventorySpaceTable" lay-filter="wcabCellinventorySpaceTable"></table>
            </div>
        </div>
    </div>

</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laypage'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        let laypage = layui.laypage;
        let viewNavPageCount = 0, listText = 0; //viewNavPageCount(图文状态下的页码)  listText(区分图文视图1 和 列表视图0)
        let viewNavBoxList = new Map();

        // 渲染表格
        var insTb = table.render({
            elem: '#wcabCellSingleinventoryProductTable',
            url: config.base + 'enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'}
                , {field: 'cabCode', sort: true, title: '柜子编号'}
                , {field: 'skuName', sort: true, title: '物料名称'}
                , {field: 'skuCode', sort: true, title: '物料编号'}
                , {field: 'skuSpecOld', sort: true, title: '规格编号'}
                , {field: 'productBrandName', sort: true, title: '品牌'}
                , {
                    field: 'weightTemp', sort: true, title: '可用重量', templet: function (d) {
                        if (d.weightTemp < 0) {
                            return d.weightTemp * -1;
                        }
                        return d.weightTemp;
                    }
                }
                , {
                    field: 'weightRepair', sort: true, title: '报修重量', templet: function (d) {
                        if (d.weightRepair < 0) {
                            return d.weightRepair * -1;
                        }
                        return d.weightRepair;
                    }
                }
                , {
                    field: 'weightRecycle', sort: true, title: '报废重量', templet: function (d) {
                        if (d.weightRecycle < 0) {
                            return d.weightRecycle * -1;
                        }
                        return d.weightRecycle;
                    }
                }
                , {field: 'weightUnitDesc', sort: true, title: '重量单位'}
                , {
                    field: 'quantityTemp', sort: true, title: '可用数量', templet: function (d) {
                        if (d.quantityTemp < 0) {
                            return d.quantityTemp * -1;
                        }
                        return d.quantityTemp
                    }
                }
                , {
                    field: 'quantityRepair', sort: true, title: '报修数量', templet: function (d) {
                        if (d.quantityRepair < 0) {
                            return d.quantityRepair * -1;
                        }
                        return d.quantityRepair
                    }
                }
                , {
                    field: 'quantityRecycle', sort: true, title: '报废数量', templet: function (d) {
                        if (d.quantityRecycle < 0) {
                            return d.quantityRecycle * -1;
                        }
                        return d.quantityRecycle
                    }
                }
                ,{field: 'quantityUnitDesc', sort: true, title: '数量单位'}
                // ,{field: 'businessTypeDesc', sort: true, title: '存入类型'}
                // , {field: 'quantityRepair', sort: true, title: '报修'}
                // , {field: 'quantityRecycle', sort: true, title: '报废'}
                // , {field: 'workshopNum', sort: true, title: '分布车间数'}
                // , {field: 'cabNum', sort: true, title: '称重柜数'}
                // , {field: 'spaceNum', sort: true, title: '货位数'}
                // , {field: 'status', sort: true, title: '库存状态', templet: function (d) {
                //         return '';
                //     }
                // }
                // ,{field: 'no', sort: true, title: 'no'}
                // ,{field: 'day', sort: true, title: 'day'}
                // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                // ,{field: 'statusDesc', sort: true, title: '状态'}
                // ,{field: 'checkTime', sort: true, title: '盘验时间'}
                // ,{field: 'checkUserId', sort: true, title: '盘验人id'}
                // ,{field: 'checkUserName', sort: true, title: '盘验人'}
                // ,{field: 'notifyTime', sort: true, title: '通知时间'}
                // ,{field: 'notifyUserId', sort: true, title: '通知人'}
                // ,{field: 'notifyUserName', sort: true, title: '通知人'}
                // ,{field: 'takeUserId', sort: true, title: '回收人id'}
                // ,{field: 'takeUserName', sort: true, title: '回收人'}
                // ,{field: 'takeTime', sort: true, title: '回收时间'}
                // ,{field: 'inoutId', sort: true, title: '暂存柜存刀id'}
                // ,{field: 'cabId', sort: true, title: '柜子id'}
                // ,{field: 'skuId', sort: true, title: 'sku id'}
                // ,{field: 'companyId', sort: true, title: '企业id'}
                // ,{field: 'spaceId', sort: true, title: '货道id'}
                // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                // ,{field: 'quantityCurrent', sort: true, title: '当前库存'}
                // ,{field: 'quantityAfter', sort: true, title: '变动后库存'}

                , {align: 'center', toolbar: '#wcabCellSingleinventoryProductTableBar', title: '操作', width: 200}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                /* var menuButton = config.getMenuButton(location.hash);
                 if(menuButton.indexOf("搜索") == -1){
                     $('.layui-form.toolbar').remove();
                 }
                 if(menuButton.indexOf("修改") == -1){
                     $("[lay-event='edit']").remove();
                 }
                 if(menuButton.indexOf("删除") == -1){
                     $("[lay-event='del']").remove();
                 }*/
            }
        });

        // 工具条点击事件
        table.on('tool(wcabCellSingleinventoryProductTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event == 'detail') {
                showEditModel(data);
            } else if (obj.event == 'inventorySpace') {
                showInventorySpaceModel(data)
            }
        });


        //监听排序
        table.on('sort(wcabCellSingleinventoryProductTable)', function (obj) {
            table.reload('wcabCellSingleinventoryProductTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        $('#viewNav .viewNavGraphics ').click(function () {
            listText = 1;
            $(this).addClass('active').siblings().removeClass('active');
            $(this).find('img').attr('src', 'assets/images/navgraphics1.png');
            $(this).siblings('div').eq(0).find('img').attr('src', 'assets/images/navlist.png');
            $('[lay-id="wcabCellSingleinventoryProductTable"]').hide();
            $('#viewNavMain').show();
        });

        $('#viewNav .viewNavList ').click(function () {
            listText = 0;
            $('[lay-id="wcabCellSingleinventoryProductTable"]').show();
            $('#viewNavMain').hide();
            $(this).addClass('active').siblings().removeClass('active');
            $(this).find('img').attr('src', 'assets/images/navlist1.png');
            $(this).siblings('div').eq(0).find('img').attr('src', 'assets/images/navgraphics.png');
        });

        function viewNavBox(data) {
            layer.load(2);
            let html = '';
            if (!data || data.length <= 0) {
                $('#viewNavBox').html(html);
                $('#viewNavPage').hide();
            } else {
                for (let i = 0; i < data.length; i++) {
                    viewNavBoxList.set(data[i].cabCode + data[i].skuCode, data[i]);
                    html += `<div class="viewNavBoxList" id="${data[i].cabCode + data[i].skuCode}">
                            <div class="viewNavBoxSpaceNum">${data[i].spaceNum}</div>
                            <div class="viewNavBoxListImg"><img src="${data[i].skuPic}" alt=""></div>
                            <div class="viewNavBoxListTitle">${data[i].skuSpec}</div>
                            <div class="viewNavBoxListBottom"><span>${data[i].skuCode}</span><span>${data[i].quantity}</span></div>
                        </div>`
                }
                $('#viewNavPage').show();
                $('#viewNavBox').html(html);
            }
            layer.closeAll();

        }

        admin.reqSync('enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list', {page: 1, limit: 21}, res => {
            if (res.code === 200) {
                viewNavPageCount = res.count;
                viewNavBox(res.data);
                viewNavPageFn()
            }
        }, 'get');

        function viewNavPageFn(_condition) {
            laypage.render({
                elem: 'viewNavPage' //注意，这里的 test1 是 ID，不用加 # 号
                , count: viewNavPageCount //数据总数，从服务端得到
                , limit: 21
                , jump: function (obj, first) {
                    if (!first) {
                        let condition = _condition ? $.extend(_condition, {
                            page: obj.curr,
                            limit: obj.limit
                        }) : {page: obj.curr, limit: obj.limit};
                        admin.req('enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list', condition, res => {
                            if (res.code === 200) {
                                viewNavBox(res.data);
                            }
                        }, 'get');
                    }
                }
            });
        }

        $('#viewNavBox').delegate('.viewNavBoxList', 'click', function () {
            showEditModel(viewNavBoxList.get($(this).attr('id')));
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            if (listText == 0) {
                insTb.reload({where: data.field, page: {curr: 1}}, 'data');
            } else {
                admin.reqSync('enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list', $.extend(data.field, {
                    page: 1,
                    limit: 21
                }), res => {
                    if (res.code === 200) {
                        viewNavPageCount = res.count;
                        viewNavBox(res.data);
                        viewNavPageFn(data.field)
                    }
                }, 'get');
            }
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            if (listText == 0) {
                insTb.reload({where: field, page: {curr: 1}}, 'data');
            } else {
                admin.reqSync('enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list', {
                    page: 1,
                    limit: 21
                }, res => {
                    if (res.code === 200) {
                        viewNavPageCount = res.count;
                        viewNavBox(res.data);
                        viewNavPageFn(field)
                    }
                }, 'get');
            }
        });


        admin.req('enterprisecab/cabProduct/admin/productType/list', {type: 'cabnet', limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择称重柜类型</option>';
                for (var k = 0; k < res.data.length; k++) {
                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='productType']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        admin.req('enterprisecab/cabProduct/admin/productBrand/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择称重柜品牌</option>';
                for (var k = 0; k < res.data.length; k++) {
                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='productBrandId']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        admin.req('enterprisecab/cabinet/admin/cabinet/list', {limit:999,cabinetNature:'live'}, function (res) {
            if (200 == res.code) {
                var optionHtml='<option value=""> 请选择称重柜</option>';
                for(var k=0;k<res.data.length;k++){
                    optionHtml+='<option value="'+res.data[k].code+'">'+res.data[k].code+'</option>';
                }
                $("select[name='cabCode']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        form.render('select');

        // 添加按钮点击事件
        $('#storageInventoryInoutBtnAdd').click(function () {
            showEditModel();
        });

        function showInventorySpaceModel(data) {
            admin.open({
                type: 1,
                area: '1580px',
                offset: '65px',
                title: '库存分布',
                content: $('#inventorySpaceTab').html(),
                success: function () {
                    getInventorySpace(data);

                }
            })
        }

        function getInventorySpace(data) {
            // 渲染表格
            var insTb = table.render({
                elem: '#wcabCellinventorySpaceTable',
                url: config.base + 'enterprisecab/wcabinet/admin/wcabCellInventorySpace/list4SingleInventoryDetail?cabCode4Detail=' + data.cabCode + '&skuCode4Detail=' + data.skuCode,
                page: true,
                cellMinWidth: 100,
                cols: [[
                    {type: 'numbers'}

                    , {field: 'spaceCode', sort: true, title: '货道编号',templet:function (d) {
                            return d.cabCode+'-'+d.spaceCode;
                        }}
                    , {field: 'cabCode', sort: true, title: '柜子编号'}

                    , {field: 'skuName', sort: true, title: '物料名称'}
                    , {field: 'skuCode', sort: true, title: '物料编号'}
                    , {
                        field: 'businessType', sort: true, title: '存入类型', templet: function (d) {
                            if (d.businessType == 'normal') {
                                return '可用';
                            } else if (d.businessType == 'repair') {
                                return '报修'
                            } else if (d.businessType == 'recycle') {
                                return '报废'
                            } else {
                                return '';
                            }
                        }
                    }
                    , {field: 'weight', sort: true, title: '重量'}
                    , {field: 'weightUnitDesc', sort: true, title: '重量单位'}
                    , {field: 'quantity', sort: true, title: '数量'}
                    , {field: 'quantityUnitDesc', sort: true, title: '数量单位'}
                    , {field: 'weightMax', sort: true, title: '最大承重'}
                    // , {field: 'checkStatusDesc', sort: true, title: '盘验状态'}
                    // ,{field: 'unitName', sort: true, title: '单位'}
                    // , {
                    //     field: 'status', sort: true, title: '盘验状态', templet: function (d) {
                    //         if (d.status == 'created') {
                    //             return '待盘验'
                    //         }
                    //         return '已盘验'
                    //     }
                    // }
                    // ,{field: 'no', sort: true, title: 'no'}
                    // ,{field: 'day', sort: true, title: 'day'}
                    // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                    // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                    // ,{field: 'statusDesc', sort: true, title: '状态'}
                    // ,{field: 'checkTime', sort: true, title: '盘验时间'}
                    // ,{field: 'checkUserId', sort: true, title: '盘验人id'}
                    // ,{field: 'checkUserName', sort: true, title: '盘验人'}
                    // ,{field: 'notifyTime', sort: true, title: '通知时间'}
                    // ,{field: 'notifyUserId', sort: true, title: '通知人'}
                    // ,{field: 'notifyUserName', sort: true, title: '通知人'}
                    // ,{field: 'takeUserId', sort: true, title: '回收人id'}
                    // ,{field: 'takeUserName', sort: true, title: '回收人'}
                    // ,{field: 'takeTime', sort: true, title: '回收时间'}
                    // ,{field: 'inoutId', sort: true, title: '暂存柜存刀id'}
                    // ,{field: 'cabId', sort: true, title: '柜子id'}
                    // ,{field: 'skuId', sort: true, title: 'sku id'}
                    // ,{field: 'companyId', sort: true, title: '企业id'}
                    // ,{field: 'spaceId', sort: true, title: '货道id'}
                    // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                    // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                    // ,{field: 'quantityCurrent', sort: true, title: '当前库存'}
                    // ,{field: 'quantityAfter', sort: true, title: '变动后库存'}

                    // ,{align: 'center', toolbar: '#wcabCellSingleinventoryProductTableBar', title: '操作', width: 200}
                ]],
                done: function (res, curr, count) {
                    //移除按钮
                    var menuButton = config.getMenuButton(location.hash);
                    if (menuButton.indexOf("搜索") == -1) {
                        $('.layui-form.toolbar').remove();
                    }
                    if (menuButton.indexOf("修改") == -1) {
                        $("[lay-event='edit']").remove();
                    }
                    if (menuButton.indexOf("删除") == -1) {
                        $("[lay-event='del']").remove();
                    }
                }
            });

            // 工具条点击事件
            table.on('tool(wcabCellinventorySpaceTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') { //修改
                    showEditModel(data);
                } else if (obj.event === 'del') { // 删除
                    doDelete(obj);
                }
            });

            //监听排序
            table.on('sort(wcabCellinventorySpaceTable)', function (obj) {
                table.reload('wcabCellinventorySpaceTable', {
                    initSort: obj
                    , where: {
                        sort: obj.field
                        , order: obj.type
                    }
                });
            });

            // 搜索
            form.on('submit(formSubSearchLog)', function (data) {
                insTb.reload({where: data.field, page: {curr: 1}}, 'data');
            });
        }

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '880px',
                offset: '65px',
                title: '详情',
                content: $('#storageInventoryInoutForm').html(),
                success: function () {
                    if (data) {
                        var option = $("form select[name='operationType']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.operationType == item.text) {
                                data.operationType = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='businessType']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.businessType == item.text) {
                                data.businessType = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='status']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.status == item.text) {
                                data.status = item.value;
                            }
                        });
                    }

                    $(".model-form input").css("border", "none")
                    $(".model-form input").attr('readonly', true);
                    $('#skuPic').attr('src', data.skuPic);
                    form.val('storageInventoryInoutForm', data);
                    // 表单提交事件
                    form.on('submit(storageInventoryInoutFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprisecab/cabinet/admin/storageInventoryInout/update' : 'enterprisecab/cabinet/admin/storageInventoryInout/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('wcabCellSingleinventoryProductTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/cabinet/admin/storageInventoryInout/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        /*$('#storageInventoryInoutBtnExport').click(function () {
            var checkRows = table.checkStatus('wcabCellSingleinventoryProductTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });*/
        $('#storageInventoryInoutBtnExport').click(function () {
            layer.load(2);
            let d = {page: 1, limit: 9999999}, t = layui.$('#exportFrom [name]').serializeArray();
            layui.$.each(t, function () {
                d[this.name] = this.value;
            });

            admin.req('enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list', d, res => {
                layer.closeAll('loading');
                if (res.code === 200) {
                    table.exportFile(insTb.config.id, res.data, 'xls', '重力柜库存管理(按智能柜)');
                } else {
                    layer.msg('导出失败', {icon: 2})
                }
            });

        });

    });
</script>